/**
 * Created by q on 2016/10/11.
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
import store from '../vuex'

Vue.use(VueRouter)
const router = new VueRouter({
  // mode: 'history',
  routes
})

router.beforeEach((to, from, next) => {
  // if (to.path == '/login') {
  //   sessionStorage.removeItem('user');
  // }
  // let user = JSON.parse(sessionStorage.getItem('user'));
  if (!store.state.isLogin && to.path !== '/login') {
    next({ path: '/login' })
  } else {
    next()
  }
})
// router.beforeEach((to, from, next) => {
//
//   if (to.matched.some(record => record.meta.requiresAuth)) {
//     // this route requires auth, check if logged in
//     // if not, redirect to login page.
//     if (!store.state.auth.isLogin) {
//       next( '/login' )
//     } else {
//       next()
//     }
//   } else {
//
//     next() // make sure to always call next()!
//   }
// })

export default router
